﻿using RSALicCore;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RSALicUI
{
    /// <summary>
    /// 生成二维码的控件(带标题)
    /// </summary>
    public partial class QRMakerExCtrl : UserControl, IQRMaker
    {
        public QRMakerExCtrl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title
        {
            get => groupBox1.Text;
            set => groupBox1.Text = value;
        }

        public Image GetQrImage()
        {
            return qr.GetQrImage();
        }

        /// <summary>
        /// 设置需要以二维码显示的数据内容
        /// </summary>
        /// <param name="data"></param>
        public void SetData(string data)
        {
            qr.SetData(data);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // 默认加载本机的特征数据
            GetLocalData();
        }

        void GetLocalData()
        {
            var pm = new PubLicManager(CommResources.PubKey);
            var hardwareHash = RSALicCore.HardwareInfoReader.Read();
            var plic = pm.MakeLic(hardwareHash);
            qr.SetData(plic);
        }
    }
}
